﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace SharePoint.Contrib.Extensions
{
    /// <summary>
    /// Extension methods for the SPListCollection class
    /// </summary>
    public static class SPListCollectionExtensions
    {

        /// <summary>
        /// Determines whether a list with the specified name (internal name, aka RootFolder.Name) is in the collection.
        /// </summary>
        /// <param name="name">The internal name, aka RootFolder.Name</param>
        public static bool Contains(this SPListCollection instance, string name)
        {
            return instance
                .Contains(spl => spl.Name() == name);

        }

        /// <summary>
        /// Determines whether a list with the specified id is in the collection.
        /// </summary>
        /// <param name="id">The id of the list</param>
        public static bool Contains(this SPListCollection instance, Guid id)
        {
            return instance
                .Contains(spl => spl.ID == id);

        }

        /// <summary>
        /// Determines whether the specified SPList can be found in the collection.
        /// </summary>
        /// <param name="func">The delegate to use to search</param>
        public static bool Contains(this SPListCollection instance, Func<SPList, bool> match)
        {
            return instance
                .Cast<SPList>()
                .Any(match);
        }

    }
}
